package com.hhj.king.provider.cloud;

import com.netflix.appinfo.HealthCheckHandler;
import com.netflix.appinfo.InstanceInfo.InstanceStatus;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.health.Status;
import org.springframework.stereotype.Component;

/**
 * @author KING
 * @date 2018/10/9 20:34
 */
@Component
@Slf4j
public class MyHealthCheckHandler implements HealthCheckHandler {

    @Autowired
    public MyHealthIndicator myHealthIndicator;

    @Override
    public InstanceStatus getStatus(InstanceStatus instanceStatus) {
        Status state = myHealthIndicator.health().getStatus();
        if (state.equals(Status.UP)) {
            log.info("数据连接成功...");
            return InstanceStatus.UP;
        } else {
            log.info("数据连接失败...");
            return InstanceStatus.DOWN;
        }

    }
}
